﻿namespace CoreClass
{
    using System;
    using System.IO;

    internal class Mk_log
    {
        internal Mk_log()
        {
        }

        internal void logToDataBase(int userid, string username, string mk_num, string msg, string Logtime)
        {
            string strSql = string.Concat(new object[] { "insert mk_rizhi(id2,user_name,mk_num,addtime,operation) values(", userid, ",'", username, "','", mk_num, "','", Logtime, "','", msg, "')" });
            new DBCommon().ExcuteSql(strSql);
        }

        internal void logToTextFile(string path, string msg, string source)
        {
            if (((path != null) && (msg != null)) && (source != null))
            {
                try
                {
                    if (File.Exists(path))
                    {
                        if (new FileInfo(path).Length < Mk_log_config.LogMaxSize)
                        {
                            this.WriteToFile(path, msg, source);
                        }
                    }
                    else
                    {
                        this.WriteToFile(path, msg, source);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("\u5199\u5165\u6587\u4ef6\u65f6\u51fa\u73b0\u5f02\u5e38: " + e);
                }
            }
        }

        private void WriteToFile(string path, string msg, string source)
        {
            StreamWriter sw = new StreamWriter(path, true);
            sw.Write(source + msg);
            sw.Close();
        }
    }
}

